home *** CD-ROM | disk | FTP | other *** search
- Path: news.iag.net!news
- From: jatmon@iag.net (John R Buchan)
- Newsgroups: comp.lang.c
- Subject: Re: char* to char array[] ?
- Date: 12 Jan 1996 21:08:58 GMT
- Organization: Internet Access Group, Orlando, Florida
- Message-ID: <4d6ila$g4r@news.iag.net>
- References: <4d4n9s$9uv@ixnews2.ix.netcom.com>
- NNTP-Posting-Host: pm1-orl25.iag.net
- X-Newsreader: WinVN 0.99.7
-
- In article <4d4n9s$9uv@ixnews2.ix.netcom.com>, tstevens@ix.netcom.com says...
- >
- > My situation is this: I have a routine which needs to return a
- >char string:
- >
- >char * called_function() {
-
- You will find several solutions (direct and indirect) for this in the c.l.c
- faq (Frequently Asked Question) list. It is available for anonymous ftp
- from rtfm.mit.edu /pub/usenet/comp.lang.c.
-
- Basically, you can:
-
- 1. Have the function malloc a char array and return a pointer to it.
- The caller will have to free this memory later.
-
- 2. Define a static char array within the function and return a pointer
- to it. Since only one copy of the array will exist, any modification
- made to it will appear at all pointers returned by the function.
-
- 3. define a global char array and have the function return a pointer
- to it. Same problem as above.
-
- 4. Define an automatic char array within the function, return a pointer
- to it, and see how long it takes to crash the program. :-)
-
- --
- John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
- jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
-
-